/*
 * Line.cpp
 *
 *  Created on: Feb 7, 2012
 *      Author: frc3928
 */

#include "Line.h"

Line::Line()
{
	//printf("making");
}

Line::Line(CvPoint pt1, CvPoint pt2) {
	if (pt1.x != pt2.x)
	{
		Slope = (pt2.y - pt1.y) / (pt2.x - pt1.x); //TODO something with passing points to constructor is wrong. Fix it.
	}
	else
	{
		Slope = -500;
	}
	Intercept = pt1.y - (Slope*pt1.x);
}

void Line::createLine(CvPoint pt1, CvPoint pt2) {
	Slope = (pt2.y - pt1.y) / (pt2.x - pt1.x);
	Intercept = pt1.y - (Slope*pt1.x);
}

cv::Point2f Line::getIntersectionWith(Line otherLine)
{
	if (Slope == otherLine.Slope)
	{
		return cvPoint2D32f(-1, -1);
	}
	double intersectionX = (Intercept - otherLine.Intercept) / (otherLine.Slope - Slope);
	double intersectionY = (Slope * intersectionX) + Intercept;

	cv::Point2f intersectionPoint = cvPoint2D32f(intersectionX, intersectionY);
	return intersectionPoint;
}

Line::~Line() {
	// TODO Auto-generated destructor stub
}

